#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<stdlib.h>


int main()
{
    pid_t pid = fork();
    if(pid == 0)
    {
        printf("I am child process, my pid : %d, my ppid : %d\n",getpid(),getppid()); //这里加上/n进行行刷新，否则就会存在输出缓冲区中，之后程序替换数据和代码部分要进行写时拷贝，更改页表，新进程的缓冲区就为空了。进程的独立性！！！
        execl("/bin/ls","ls","-a","-l",NULL);
        printf("execl success");
    }
    else 
    {
        int status;
        pid_t rid = waitpid(-1,&status,0);   
        if(rid > 0)
        {
            printf("wait success,pid : %d ,exit code is %d, exit sig is %d\n",rid,(status >> 8)& 0xff,status & 0x7f);
        }
        else
        {
            printf("wait failure");
        }
    }

    return 0;
}
